﻿using System;
using TSites.Common.Enums;
using TSites.Core.Domain.UserMangerment;
using TSites.Common.Const;

namespace TSites.Administrator.Models
{
    public class AdminEntity
    {
        public string UserId { get; set; }
        public string Username { get; set; }
        public string Email { get; set; }
        public DateTime? LastestLogon { get; set; }
        public ACTIVE_CODE ActiveCode { get; set; }
    }

    public interface IAdminSession
    {
        AdminEntity CurrentAdmin { get; }
        void Add2Session(User currentUser);
    }

    public class AdminSession : IAdminSession
	{
        public AdminEntity CurrentAdmin
        { get { return (AdminEntity)System.Web.HttpContext.Current.Session[StringConst.USER_SESSION]; } }
        
        public void Add2Session(User currentUser)
		{
            AdminEntity currentAdmin = new AdminEntity()
            {
                UserId = currentUser.ID,
                Username = currentUser.UserName,
                Email = currentUser.Email,
                LastestLogon = currentUser.LastLoginDate,
                ActiveCode = (ACTIVE_CODE)currentUser.ActiveCode
            };
            System.Web.HttpContext.Current.Session[StringConst.USER_SESSION] = currentAdmin;
		}
	}
}